﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Logic;
using Entities;

namespace Presentation
{
	public partial class TaskDialogAddList : Form
	{
		private bool closing = true;
		private MovieList list = new MovieList();

		public MovieList List
		{
			get { return list; }
			set { list = value; }
		}

		public TaskDialogAddList()
		{
			InitializeComponent();
		}

		private void buttonCancel_Click(object sender, EventArgs e)
		{
			DialogResult = DialogResult.Cancel;
		}

		private void buttonAdd_Click(object sender, EventArgs e)
		{
			if (textBoxName.Text.Trim() != "")
			{
				list.Name = textBoxName.Text.Trim();

				ListBL bl = new ListBL();
				if (bl.Save(list))
				{
					MessageBox.Show("The list was added successfully", "Add list", MessageBoxButtons.OK, MessageBoxIcon.Information);

					DialogResult = DialogResult.OK;
					closing = true;
				}
				else
					closing = false;
			}
			else
			{
				MessageBox.Show("You need put a name to the list", "Add list", MessageBoxButtons.OK, MessageBoxIcon.Warning);
				closing = false;
			}
		}

		private void TaskDialogAddList_FormClosing(object sender, FormClosingEventArgs e)
		{
			if (!closing)
			{
				closing = true;
				e.Cancel = true;
			}
		}
	}
}